package t327.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import t327.pojo.Client;
import t327.pojo.TakeAwaySubmit;
import t327.pojo.font.LuiTableEntity;
import t327.pojo.until.Result;
import t327.service.iter.IAuditService;

import java.util.List;

@Controller
@RequestMapping("Audits")
public class AuditController {
    @Autowired
    private IAuditService iAuditService;

    @RequestMapping("getTakeAwaySubmitInfo")
    @ResponseBody
    private LuiTableEntity getTakeAwaySubmitInfo(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit") Integer pageSize) {
        List<TakeAwaySubmit> takeAwaySubmit1 = iAuditService.queryAll();
        LuiTableEntity luiTableEntity = new LuiTableEntity<TakeAwaySubmit>();
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<TakeAwaySubmit> menuPageInfo = new PageInfo<>(takeAwaySubmit1);
        List<TakeAwaySubmit> takeAwaySubmits = menuPageInfo.getList();
        long total = menuPageInfo.getTotal();
        if (takeAwaySubmits != null && takeAwaySubmits.size() > 0) {
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(takeAwaySubmits);
        } else {
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");
        }
        return luiTableEntity;

    }


    @RequestMapping("deleteAuditById")
    @ResponseBody
    public Result deleteAuditById(Long id) {
        int i = iAuditService.deleteAuditById(id);
        System.out.println(i + "修改结果");
        if (i > 0) {
            return Result.success();
        } else {
            return new Result(202, "删除失败", false, null);
        }

    }

    @RequestMapping("updateTakeAwaySubmit")
    @ResponseBody
    public String updateTakeAwaySubmit(Long auditId,Long takeAwayStatus) {

//        Long id = takeAwaySubmit.getId();
//        Long takeAwayStatus = takeAwaySubmit.getTakeAwayStatus();

        int result = iAuditService.updateTakeAwaySubmit(auditId,takeAwayStatus);

        if (result > 0) {
            return "success";
        } else {
            return "failure";
        }
    }

//    @RequestMapping(value = "/approve/{id}", method = RequestMethod.POST)
//    public ResponseEntity<String> approveAudit(@PathVariable Long id) {
//        int result = iAuditService.approveAudit(id);
//        if (result > 0) {
//            return ResponseEntity.ok("审核通过");
//        } else {
//            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("审核失败");
//        }
//    }
//
//    @RequestMapping(value = "/reject/{id}", method = RequestMethod.POST)
//    public ResponseEntity<String> rejectAudit(@PathVariable Long id) {
//        int result = iAuditService.rejectAudit(id);
//        if (result > 0) {
//            return ResponseEntity.ok("审核未通过");
//        } else {
//            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("审核失败");
//        }
//    }

}
